package com.hiwhitley.easy.day27;

/**
 * Created by hiwhitley on 2016/10/27.
 */
public class ShuffleAnArray_384 {
    private int[] nums;
    public ShuffleAnArray_384(int[] nums) {
        this.nums = nums;
    }

    /** Resets the array to its original configuration and return it. */
    public int[] reset() {
        return nums;
    }

    /** Returns a random shuffling of the array. */
    public int[] shuffle() {
        int[] rand = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            int r = (int) (Math.random() * (i + 1));
            rand[i] = rand[r];
            rand[r] = nums[i];
        }

        return rand;
    }

    public static void main(String[] args) {
        ShuffleAnArray_384 main = new ShuffleAnArray_384(new int[]{1, 2, 3});
        main.shuffle();
    }
}
